package tcdx.uap.service;

import com.alibaba.excel.EasyExcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import tcdx.uap.common.utils.Lutils;
import tcdx.uap.service.Listener.NoModleDataListener;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Service
public class ExcelService {

    @Autowired
    private BaseDBService baseDBService;

    @Transactional
    public void importExcel(MultipartFile file, int menu_id, int table_id) throws IOException {
        //导入功能，根据table_id获取字段
        List<Map> columns_list = baseDBService.selectEq("tcdx_datatable_columns",
                Lutils.genMap("table_id",table_id));

        List<Map> maps = baseDBService.selectEq("tcdx_datatable",
                Lutils.genMap("menu_id", menu_id));
        String table_name = maps.get(0).get("table_name").toString();

        String create_staff_nm = "钱文强";
        int create_staff_no = 174585;
        int dept_id=27721;

        //5.读取excel数据，和表头结构
        EasyExcel.read(file.getInputStream(),
                new NoModleDataListener(table_name,create_staff_nm,columns_list,
                        create_staff_no,dept_id,baseDBService)).sheet().doRead();

        
    }
}
